package com.woniu.order.service.impl;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.common.dto.UserDto;
import com.woniu.common.utils.PageData;
import com.woniu.common.utils.ResponseData;
import com.woniu.common.utils.ResponseEnum;
import com.woniu.common.utils.UserUtil;
import com.woniu.order.dto.ZsbAddProductDto;
import com.woniu.order.dto.ZsbOrderApplicationDetailDto;
import com.woniu.order.dto.ZsbPowerUserDto;
import com.woniu.order.dto.ZsbProductDto;
import com.woniu.order.feign.ZsbProductFeign;
import com.woniu.order.feign.ZsbUumsFeign;
import com.woniu.order.mapper.ZcxOrderDetailsMapper;
import com.woniu.order.mapper.ZsbJwtMapper;
import com.woniu.order.pojo.*;
import com.woniu.order.service.ZsbOrderApplicationService;
import com.woniu.order.mapper.ZsbOrderApplicationMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author 25429
 * @description 针对表【zsb_order_application】的数据库操作Service实现
 * @createDate 2024-11-24 18:22:53
 */
@Service
public class ZsbOrderApplicationServiceImpl extends ServiceImpl<ZsbOrderApplicationMapper, ZsbOrderApplication>
        implements ZsbOrderApplicationService {
    @Autowired
    private ZsbOrderApplicationMapper zsbOrderApplicationMapper;
    @Autowired
    private ZsbProductFeign zsbProductFeign;
    @Autowired
    private ZsbUumsFeign zsbUumsFeign;
    @Autowired
    private ZsbJwtMapper zsbJwtMapper;
    @Autowired
    private ZcxOrderDetailsMapper zcxOrderDetailsMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public ResponseData<?> queryAllCustomer() {
        return new ResponseData<>().ok(zsbOrderApplicationMapper.queryAllCustomer());
    }

    @Override
    public ResponseData<?> createSnowId() {
        Snowflake snowflake = IdUtil.getSnowflake();
        String snowId = "DDSQ" + snowflake.nextId();
        return new ResponseData<>().ok(snowId);
    }

    @Override
    public ResponseData<?> queryAllProduct() {
        ResponseData<?> responseData = zsbProductFeign.queryAllProduct();
        return new ResponseData<>().ok(responseData.getData());
    }

    @Override
    public ResponseData<?> addOrderApplicationProduct(ZsbAddProductDto zsbAddProductDto) {

        List<ZsbProductDto> tableData = zsbAddProductDto.getTableData();
        for (ZsbProductDto tableDatum : tableData) {
            ZsbOrderApplicationProduct zsbOrderApplicationProduct = new ZsbOrderApplicationProduct();
            zsbOrderApplicationProduct.setOrderApplicationCode(zsbAddProductDto.getOrderCode());
            zsbOrderApplicationProduct.setProductCode(tableDatum.getProductCode());
            zsbOrderApplicationProduct.setProductName(tableDatum.getProductName());
            zsbOrderApplicationProduct.setProductStock(tableDatum.getProductStock().toString());
            zsbOrderApplicationProduct.setProductCount(tableDatum.getCount().toString());
            zsbOrderApplicationProduct.setProductDescription(tableDatum.getProductDescription());
            zsbOrderApplicationProduct.setProductPrice(tableDatum.getProductPrice());
            zsbOrderApplicationMapper.addOrderApplicationProduct(zsbOrderApplicationProduct);
        }

        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> getPrice(String code) {
        List<ZsbOrderApplicationProduct> zsbOrderApplicationProducts = zsbOrderApplicationMapper.queryByCode(code);
        BigDecimal sum = new BigDecimal(0);
        for (ZsbOrderApplicationProduct zsbOrderApplicationProduct : zsbOrderApplicationProducts) {
            BigDecimal productPrice = zsbOrderApplicationProduct.getProductPrice();
            String productCount = zsbOrderApplicationProduct.getProductCount();
            sum = sum.add(productPrice.multiply(new BigDecimal(productCount)));
        }
        BigDecimal multiply = sum.multiply(new BigDecimal(0.17));
        ZsbOrderApplication zsbOrderApplication = new ZsbOrderApplication();
        zsbOrderApplication.setOrderPrice(sum);
        zsbOrderApplication.setTax(multiply);
        return new ResponseData<>().ok(zsbOrderApplication);
    }

    @Override
    public ResponseData<?> addOrderApplication(ZsbOrderApplication zsbOrderApplication) {
        List<ZsbOrderApplicationProduct> zsbOrderApplicationProducts = zsbOrderApplicationMapper.queryByCode(zsbOrderApplication.getCode());
        //todo 判断在提交时库存是否足够 返回失败值   有时间再做
        //减产品库存逻辑  调hht的接口
        for (ZsbOrderApplicationProduct zsbOrderApplicationProduct : zsbOrderApplicationProducts) {
            zsbProductFeign.reduceStock(zsbOrderApplicationProduct.getProductCode(), Integer.parseInt(zsbOrderApplicationProduct.getProductCount()));
        }


        //添加订单申请表
        Snowflake snowflake = IdUtil.getSnowflake();
        String ordNum = "ORD" + snowflake.nextId();
        zsbOrderApplication.setOrderNum(ordNum);
        zsbOrderApplication.setStatus("0");
        zsbOrderApplicationMapper.addOrderApplication(zsbOrderApplication);

        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        JSONObject orderJson = new JSONObject();
        orderJson.put("orderNum", zsbOrderApplication.getCode());
        orderJson.put("approver",zsbOrderApplication.getApprover());
        this.sendMessage("order.exchange","ecp.ttl.queue.key",orderJson.toString());
        return new ResponseData<>().ok();
    }


    @Override
    public ResponseData<?> queryJLWeiShenPi(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        String status = "0";
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setStatus(status);
        pageData.getParam().setApprover(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.queryAllWeiShenPi(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> queryJLYiShenPi(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        String status = "0";
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setStatus(status);
        pageData.getParam().setApprover(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.queryAllYiShenPi(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }


    @Override
    public ResponseData<?> refuseApplication(ZsbOrderApplication zsbOrderApplication) {
        List<ZsbOrderApplicationProduct> zsbOrderApplicationProducts = zsbOrderApplicationMapper.queryByCode(zsbOrderApplication.getCode());

        //回滚产品库存逻辑  调hht的接口
        for (ZsbOrderApplicationProduct zsbOrderApplicationProduct : zsbOrderApplicationProducts) {
            zsbProductFeign.rollbackStock(zsbOrderApplicationProduct.getProductCode(), Integer.parseInt(zsbOrderApplicationProduct.getProductCount()));
        }


        zsbOrderApplicationMapper.updateApplicationStatus(zsbOrderApplication);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> passjlApplication(ZsbOrderApplication zsbOrderApplication) {
        zsbOrderApplicationMapper.updateApplicationStatus(zsbOrderApplication);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> querySaleWeiShenPi(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setSaleCode(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.querySaleWeiShenPi(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> querySaleTongGuo(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setSaleCode(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.querySaleTongGuo(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> querySaleRefuse(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setSaleCode(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.querySaleRefuse(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> queryZJWeiShenPi(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        String status = "2";
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setStatus(status);
        pageData.getParam().setApproverZJ(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.queryZJWeiShenPi(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> queryZJYiShenPi(PageData<ZsbOrderApplication> pageData) {
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());
        ZsbJwt zsbJwt = zsbJwtMapper.queryJwtZsbJwt();
        UserDto user = UserUtil.getUser(zsbJwt.getJwt());
        String approver = user.getId().toString();
        pageData.getParam().setApproverZJ(approver);
        List<ZsbOrderApplication> zsbOrderApplications = zsbOrderApplicationMapper.queryZJYiShenPi(pageData.getParam());
        for (ZsbOrderApplication zsbOrderApplication : zsbOrderApplications) {
            ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(zsbOrderApplication.getSaleCode());
//            ZsbPowerUserDto data = (ZsbPowerUserDto) responseData.getData();
            zsbOrderApplication.setSaleCode(zsbPowerUserDto.getRealName());
            Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(zsbOrderApplication.getCustomerCode());
            zsbOrderApplication.setCustomerCode(customer.getCustomerName());
        }
        PageInfo pageInfo = new PageInfo(zsbOrderApplications);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> addOrder(ZsbOrderApplication zsbOrderApplication) {

        //添加订单产品表
        List<ZsbOrderApplicationProduct> zsbOrderApplicationProducts = zsbOrderApplicationMapper.queryByCode(zsbOrderApplication.getCode());
        for (ZsbOrderApplicationProduct zsbOrderApplicationProduct : zsbOrderApplicationProducts) {
            ZcxOrderDetails zcxOrderDetails = new ZcxOrderDetails();
            ZsbOrderApplication zsbOrderApplication1 = zsbOrderApplicationMapper.queryByOrderApplicationCode(zsbOrderApplication.getCode());
            zcxOrderDetails.setOrderCode(zsbOrderApplication1.getOrderNum());
            zcxOrderDetails.setProductCode(zsbOrderApplicationProduct.getProductCode());
            zcxOrderDetails.setProductName(zsbOrderApplicationProduct.getProductName());
            zcxOrderDetails.setPlaceOrderNum(zsbOrderApplicationProduct.getProductCount());
            zcxOrderDetails.setUnit("件");
            zcxOrderDetails.setUnivalent(zsbOrderApplicationProduct.getProductPrice());
            zcxOrderDetails.setPrice(zsbOrderApplicationProduct.getProductPrice().multiply(new BigDecimal(zsbOrderApplicationProduct.getProductCount())));
            zcxOrderDetails.setStatus("0");
            zsbOrderApplicationMapper.addOrderDetail(zcxOrderDetails);
        }


        //添加订单表
        ZsbOrderApplication orderApplication = zsbOrderApplicationMapper.queryByOrderApplicationCode(zsbOrderApplication.getCode());
        ZcxCustomerOrder zcxCustomerOrder = new ZcxCustomerOrder();
        zcxCustomerOrder.setOrderCode(orderApplication.getOrderNum());
        zcxCustomerOrder.setDepositAmount(orderApplication.getDepositAmount());
        zcxCustomerOrder.setDeposit(orderApplication.getDeposit());
        zcxCustomerOrder.setPayment(orderApplication.getPayment());
        zcxCustomerOrder.setStatus(1);
        if (orderApplication.getDeposit().equals("0")){
            zcxCustomerOrder.setOrderType(0);
        }
        if (orderApplication.getDeposit().equals("1")){
            zcxCustomerOrder.setOrderType(1);
        }

        zcxCustomerOrder.setSalespersonCode(orderApplication.getSaleCode());
        zcxCustomerOrder.setSpecialDiscount(orderApplication.getDiscount());
        zcxCustomerOrder.setTaxAmount(orderApplication.getTax());
        zcxCustomerOrder.setTotalPrice(orderApplication.getOrderPrice());
        zcxCustomerOrder.setCustomerCode(orderApplication.getCustomerCode());


        Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(orderApplication.getCustomerCode());
        zcxCustomerOrder.setCustomerName(customer.getCustomerName());
        zcxCustomerOrder.setCustomerPhone(customer.getContactPhone());

        ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(orderApplication.getSaleCode());
        zcxCustomerOrder.setSalespersonName(zsbPowerUserDto.getRealName());


        // 先将ISO 8601格式的字符串（带有时区信息）转换为Instant对象
        LocalDateTime localDateTime = LocalDateTime.ofInstant(java.time.Instant.parse(orderApplication.getApplicationDate()), ZoneOffset.UTC);
        // 定义目标格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 进行格式化
        String formattedDateTime = localDateTime.format(formatter);
        zcxCustomerOrder.setApplicationDate(formattedDateTime);


        zcxCustomerOrder.setApplicationReason(orderApplication.getApplicationReason());
        zcxCustomerOrder.setCreatePerson(zsbPowerUserDto.getRealName());
        zsbOrderApplicationMapper.addOrder(zcxCustomerOrder);

        zsbOrderApplicationMapper.updateApplicationStatus(zsbOrderApplication);
        return new ResponseData<>().ok();
    }


    @Override
    public ResponseData<?> queryDetail(String code) {
        ZsbOrderApplication orderApplication = zsbOrderApplicationMapper.queryByOrderApplicationCode(code);
        List<ZsbOrderApplicationProduct> zsbOrderApplicationProducts = zsbOrderApplicationMapper.queryByCode(code);
        ZsbPowerUserDto zsbPowerUserDto = zsbUumsFeign.queryByCode(orderApplication.getSaleCode());
        Customer customer = zsbOrderApplicationMapper.queryCustomeByCode(orderApplication.getCustomerCode());

        ZsbOrderApplicationDetailDto zsbOrderApplicationDetailDto = new ZsbOrderApplicationDetailDto();
        BeanUtils.copyProperties(orderApplication,zsbOrderApplicationDetailDto);

        zsbOrderApplicationDetailDto.setSaleName(zsbPowerUserDto.getRealName());

        zsbOrderApplicationDetailDto.setCustomerName(customer.getCustomerName());
        zsbOrderApplicationDetailDto.setCustomerCompanyName(customer.getCompanyName());
        zsbOrderApplicationDetailDto.setCustomerCategory(customer.getCustomerCategory());
        zsbOrderApplicationDetailDto.setContactPhone(customer.getContactPhone());
        zsbOrderApplicationDetailDto.setContactName(customer.getContactPerson());
        zsbOrderApplicationDetailDto.setCompanyAddress(customer.getCompanyAddress());
        zsbOrderApplicationDetailDto.setDeliveryAddress(customer.getDeliveryAddress());

        zsbOrderApplicationDetailDto.setZsbOrderApplicationProductList(zsbOrderApplicationProducts);
        return new ResponseData<>().ok(zsbOrderApplicationDetailDto);
    }

    @Override
    public ResponseData<?> queryProductCount(Integer chaiFenCount, String orderCode) {
        //todo  订单拆分
        List<ZcxOrderDetails> zcxOrderDetails = zcxOrderDetailsMapper.queryOrderDetailByCode(orderCode);
        List<ZcxOrderDetails> productList = new ArrayList<>();
        int max = 0;
        for (ZcxOrderDetails orderDetails : zcxOrderDetails) {
            if (max < Integer.parseInt(orderDetails.getStatus())){
                max = Integer.parseInt(orderDetails.getStatus());
            }
        }
        for (ZcxOrderDetails zcxOrderDetail : zcxOrderDetails) {
            if (Integer.parseInt(zcxOrderDetail.getStatus()) == max ){
                productList.add(zcxOrderDetail);
            }
        }
        int count = 0;
        for (ZcxOrderDetails detail : productList) {
            count += Integer.parseInt(detail.getPlaceOrderNum());
        }
        if (chaiFenCount > count){
            return new ResponseData<>().fail(ResponseEnum.FAIL);
        }
        return null;
    }

    private <T> void sendMessage(String exchange,String routingKey,T t) {
        CorrelationData correlationData = new CorrelationData();
        Message returnedMessage = new Message(JSON.toJSONBytes(t));
        returnedMessage.getMessageProperties().setReceivedExchange(exchange);
        returnedMessage.getMessageProperties().setReceivedRoutingKey(routingKey);
        correlationData.setReturnedMessage(returnedMessage);
//        correlationData.getReturnedMessage().getMessageProperties().setReceivedExchange(ORDER_EXCHANGE);
//        correlationData.getReturnedMessage().getMessageProperties().setReceivedRoutingKey(ORDER_ROUTING_KEY);

        //return和消费者
        MessagePostProcessor messagePostProcessor = message -> {
            String token = IdUtil.fastUUID();
            redisTemplate.opsForValue().set(token,token,30, TimeUnit.SECONDS);
            message.getMessageProperties().setMessageId(token);
            return message;
        };



        rabbitTemplate.convertAndSend(exchange, routingKey, t,messagePostProcessor,correlationData);
    }



}




